import { defineStore } from 'pinia'
import { UserDto } from '@/api/user.ts'
import { DictDto } from '@/api/dict.ts'
import { Cube } from '@cubejs-client/core'

export const useUserStore = defineStore('user', {
  state: (): {
    userInfo: UserDto
    dataSource: string | null
    dicts: DictDto[]
    meta: Cube[]
  } => ({
    userInfo: {
      username: null,
      avatar: null,
      admin: false,
      role: null,
      viewId: null,
      view: {
        title: null,
      },
    },
    dataSource: null,
    dicts: [],
    meta: [],
  }),
  getters: {},
  actions: {
    setUser(user: UserDto) {
      this.userInfo = user
    },
    setDicts(dicts: DictDto[]) {
      this.dicts = dicts
    },
    resetUser() {
      this.$reset()
    },
    setMeta(cubes: Cube[]) {
      this.meta = cubes
    },
  },
})
